<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015-5-23
 * Time: 13:36
 */

namespace doumiaoduo\layer;
use yii\base\Widget;

class LayerPromptWidget extends Widget{

    public $button;

    public $title;

    public $value;

    public $from_type;//0（文本）1（密码）2（多行文本）

    public function init(){
        parent::init();
        if ($this->button === null) {
            $this->button= "['确定ok','取消']";
        }
        if ($this->title === null) {
            $this->title= '输入任何口令，并确认';
        }
        if ($this->value === null) {
            $this->value= '';
        }
        if ($this->from_type === null) {
            $this->from_type= 0;
        }
    }

    public function run()
    {
        $view = $this->getView();
        LayerAsset::register($view);
        $js_str="
            layer.config({
                extend: ['/skin/customskin/style.css'],
            });
           $(document).on('click','a[rel=dialog-add-iframe]',function(){
                layer.prompt({
                title: '".$this->title."',
                skin: 'layui-iframe-customskin',
                btn: ".$this->button.",
                value: '".$this->value."',
                formType:".$this->from_type." //prompt风格，支持0-2
                }, function(value, index, elem){
                alert(value); //得到value
                layer.close(index);
                });
           })
         ";
        $view->registerJs($js_str);
    }




}